package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import day1.Student;

/**
 * Servlet implementation class LoadData
 */
@WebServlet("/Load1")
public class LoadData extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoadData() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Student student = new Student("KMB", "km");
		//request.setAttribute("std", student);
		Student student1 = new Student("APP", "Mar Aung");
		Student student2 = new Student("BBB", "B");
		Student student3 = new Student("CCC", "C");
		Student student4 = new Student("DDD", "D");
		
		ArrayList<Student> l_stuList = new ArrayList<Student>();
		l_stuList.add(student);
		l_stuList.add(student1);
		l_stuList.add(student2);
		l_stuList.add(student3);
		l_stuList.add(student4);
		
		request.setAttribute("slist", l_stuList);
		
		HttpSession session = request.getSession();
		//session.setAttribute("obj", student1);
		RequestDispatcher rd = request.getRequestDispatcher("/student.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher rd = request.getRequestDispatcher("/student_submit.jsp");
		rd.forward(request, response);
	}

}
